﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace simulate_control.Basic
{
    #region USING
    using simulate_control.Helpers;
    using DevComponents.DotNetBar;
    #endregion

    public partial class FrmSelectOptions : Form
    {
        #region VARIABLES
        public EventHandler Handler { get; set; }
        private List<string> Data { get; set; }
        private const int OFFY = 28;
        private int FIRSTY = 9;
        private int Selected = 0;
        private Dictionary<int, string> dict = new Dictionary<int,string>();
        #endregion

        #region METHODS
        public FrmSelectOptions()
        {
            InitializeComponent();
        }

        public FrmSelectOptions(List<string> _data)
        {
            InitializeComponent();
            Data = _data;
        }

        public void InitForm()
        {
            if (Data.Count > 0)
            {
                for (int i = 0; i < Data.Count; i++)
                {
                    LabelX lbl = new LabelX
                    {
                        BackColor = System.Drawing.Color.Transparent,
                        Font = new System.Drawing.Font("Microsoft Sans Serif", 13F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(163))),
                        Location = new System.Drawing.Point(26, FIRSTY),
                        Name = "lbl" + Data[i],
                        Size = new System.Drawing.Size(98, 22),
                        TabIndex = i,
                        Text = " " + Data[i]
                    };
                    FIRSTY += OFFY;
                    if (i > 0)
                    {
                        this.Height += OFFY;
                    }
                    pnlMain.Controls.Add(lbl);
                    dict.Add(i, lbl.Name);
                }
            }
        }

        public void ProcessKeyEvent(KEY keyEvent)
        {
            if (keyEvent == KEY.ENTER)
            {
                this.Handler(this, new TransferDataEvent(Utils.GetSelectedDataItem(pnlMain, dict, Selected)));
                this.Close();
            }
            else
            {
                switch (keyEvent)
                {
                    case KEY.UP:
                        if (Selected > 0)
                        {
                            Selected--;
                        }
                        break;
                    case KEY.DOWN:
                        if (Selected < dict.Count - 1)
                        {
                            Selected++;
                        }
                        break;
                }
                Utils.ChangeSelectItem(pnlMain, dict, Selected);
            }
        }

        private void FrmSelectOptions_Load(object sender, EventArgs e)
        {
            InitForm();
            Utils.ChangeSelectItem(pnlMain, dict, 0);
        }
        #endregion
    }
}
